<template>
  <div>
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>订单管理</el-breadcrumb-item>
      <el-breadcrumb-item>订单列表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card style="margin-top: 20px;">
      <div style="margin-bottom: 15px;">
        <el-input
          placeholder="请输入内容"
          v-model="orderInfo.query"
          clearable
          style="width:400px;"
        >
          <el-button
            slot="append"
            icon="el-icon-search"
            @click="getordersData"
          ></el-button>
        </el-input>
      </div>
      <el-table :data="ordersData" border style="width: 100%">
        <el-table-column type="index" label="#" width="60"> </el-table-column>
        <el-table-column prop="order_number" label="订单编号" width="180">
        </el-table-column>
        <el-table-column prop="order_price" label="订单价格"> </el-table-column>
        <el-table-column prop="pay_status" label="是否付款">
          <template v-slot="scope">
            <el-tag v-if="scope.row.pay_status == '0'" type="danger"
              >未付款</el-tag
            >
            <el-tag v-else>已付款</el-tag>
          </template>
        </el-table-column>
        <el-table-column prop="is_send" label="是否发货"> </el-table-column>
        <el-table-column prop="create_time" label="下单时间">
          <template v-slot="scope">
            {{ scope.row.create_time | dateFormat }}
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template v-slot="scope">
            <el-button
              type="primary"
              size="mini"
              :f="scope"
              icon="el-icon-edit"
              @click="showBox"
            ></el-button>
            <el-button
              type="success"
              size="mini"
              icon="el-icon-location"
              @click="showprogress"
            ></el-button>
          </template>
        </el-table-column>
      </el-table>
    </el-card>
    <!-- 分页器 -->
    <div class="block">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="orderInfo.pagenum"
        :page-sizes="[4, 6, 8, 10]"
        :page-size="orderInfo.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </div>
    <!-- 修改地址 -->
    <el-dialog
      title="提示"
      :visible.sync="dialogVisible"
      width="30%"
      @close="addCloseDialog"
    >
      <el-form
        :model="ruleForm"
        :rules="rules"
        ref="ruleForm"
        label-width="100px"
        class="demo-ruleForm"
      >
        <el-form-item label="省市区/县" prop="address1">
          <el-cascader
            v-model="ruleForm.address1"
            :options="cityData"
          ></el-cascader>
        </el-form-item>
        <el-form-item label="详细地址" prop="address2">
          <el-input v-model="ruleForm.address2"></el-input>
        </el-form-item>
      </el-form>

      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="dialogVisible = false"
          >确 定</el-button
        >
      </span>
    </el-dialog>
    <!-- 物流进度 -->
    <el-dialog title="物流进度" :visible.sync="dialogVisible1" width="50%">
      <el-timeline>
        <el-timeline-item
          v-for="(activity, index) in progressInfo"
          :key="index"
          :timestamp="activity.time"
        >
          {{ activity.context }}
        </el-timeline-item>
      </el-timeline>
    </el-dialog>
  </div>
</template>

<script>
import cityData from "../citydata";
export default {
 
  data() {
    return {
      dialogVisible: false,
      dialogVisible1: false, //物流进度
      ordersData: [],
      orderInfo: {
        query: "",
        pagenum: 1,
        pagesize: 10,
      },
      total: 0, // 总条数
      ruleForm: {
        address1: [],
        address1: "",
      },
      rules: {
        address2: [
          { required: true, message: "请输入详细地址", trigger: "blur" },
        ],
        address1: [
          { required: true, message: "请输入省市区/县", trigger: "blur" },
        ],
      },
      cityData,
      progressInfo: [],
    };
  },
  // Vue实例创建完成以后执行 数据可用
  created() {
    this.getordersData();
  },
  // Vue模板挂载完毕以后执行  DOM节点加载完毕了（可以获取节点了）
  mounted() {},
  // keepalive 缓存进入执行
  activited() {},
  // vue组件更新完毕以后执行
  update() {},
  // 定义事件
  methods: {
    async getordersData() {
      let res = await this.$axios.get("https://www.liulongbin.top:8888/api/private/v1/orders", { params: this.orderInfo });
      console.log(res);
      let { meta, data } = res;
      if (meta.status == 200) {
        this.ordersData = data.goods;
        this.total = data.total;
      }
    },
    handleSizeChange(val) {
      // console.log(`每页 ${val} 条`);
      this.orderInfo.pagesize = val;
      this.getordersData();
    },
    handleCurrentChange(val) {
      // console.log(`当前页: ${val}`);
      this.orderInfo.pagenum = val;
      this.getordersData();
    },
    showBox() {
      this.dialogVisible = true;
    },
    addCloseDialog() {
      this.$refs.ruleForm.resetFields();
    },
    async showprogress() {
      let { data: res } = await this.$axios.get("/kuaidi/804909574412544580");
      console.log(res);
      if (res.meta.status == 200) {
        this.progressInfo = res;
        console.log(this.progressInfo);
      }

      this.dialogVisible1 = true;
    },
  },
  // 过滤器
  filter: {},
  // 计算属性
  computed: {},
  // 监听属性
  watch: {},
};
</script>

<style scoped></style>